home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-004 ms visual basic pro 30 / 4.imz / 4.IMA / ADDFIELD.FR_ / ADDFIELD.bin
Text File  |  1993-04-28  |  6KB  |  222 lines

  1. VERSION 2.00
  2. Begin Form fAddField 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Add Field"
  6.    ClientHeight    =   2055
  7.    ClientLeft      =   3000
  8.    ClientTop       =   3360
  9.    ClientWidth     =   3450
  10.    ControlBox      =   0   'False
  11.    Height          =   2460
  12.    Left            =   2940
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   2040
  17.    ScaleMode       =   0  'User
  18.    ScaleWidth      =   3480
  19.    Top             =   3015
  20.    Width           =   3570
  21.    Begin TextBox cFieldName 
  22.       BackColor       =   &H00FFFFFF&
  23.       Height          =   288
  24.       Left            =   840
  25.       TabIndex        =   1
  26.       Tag             =   "OL"
  27.       Top             =   120
  28.       Width           =   2532
  29.    End
  30.    Begin ComboBox cFieldType 
  31.       BackColor       =   &H00FFFFFF&
  32.       Height          =   288
  33.       Left            =   840
  34.       Style           =   2  'Dropdown List
  35.       TabIndex        =   4
  36.       Tag             =   "OL"
  37.       Top             =   600
  38.       Width           =   2532
  39.    End
  40.    Begin TextBox cFieldLength 
  41.       BackColor       =   &H00FFFFFF&
  42.       Enabled         =   0   'False
  43.       Height          =   288
  44.       Left            =   840
  45.       TabIndex        =   5
  46.       Tag             =   "OL"
  47.       Top             =   1080
  48.       Width           =   732
  49.    End
  50.    Begin CommandButton OkayButton 
  51.       Caption         =   "&OK"
  52.       Default         =   -1  'True
  53.       Enabled         =   0   'False
  54.       Height          =   372
  55.       Left            =   360
  56.       TabIndex        =   6
  57.       Top             =   1560
  58.       Width           =   1092
  59.    End
  60.    Begin CommandButton CancelButton 
  61.       Cancel          =   -1  'True
  62.       Caption         =   "&Close"
  63.       Height          =   372
  64.       Left            =   1920
  65.       TabIndex        =   7
  66.       Top             =   1560
  67.       Width           =   1092
  68.    End
  69.    Begin Label FieldSizeLabel 
  70.       BackColor       =   &H00C0C0C0&
  71.       Caption         =   "Size:"
  72.       Height          =   252
  73.       Left            =   120
  74.       TabIndex        =   3
  75.       Top             =   1080
  76.       Width           =   612
  77.    End
  78.    Begin Label FieldTypeLabel 
  79.       BackColor       =   &H00C0C0C0&
  80.       Caption         =   "Type:"
  81.       Height          =   252
  82.       Left            =   120
  83.       TabIndex        =   2
  84.       Top             =   600
  85.       Width           =   612
  86.    End
  87.    Begin Label FieldNameLabel 
  88.       BackColor       =   &H00C0C0C0&
  89.       Caption         =   "Name:"
  90.       Height          =   252
  91.       Left            =   120
  92.       TabIndex        =   0
  93.       Top             =   120
  94.       Width           =   612
  95.    End
  96. End
  97.  
  98. Option Explicit
  99.  
  100. Sub CancelButton_Click ()
  101.   Unload Me
  102. End Sub
  103.  
  104. Sub cFieldLength_Change ()
  105.   'activate the ok button only if all of the
  106.   'fields have something in it
  107.   If cFieldName <> "" And cFieldType <> "" And Val(cFieldLength) > 0 Then
  108.     OkayButton.Enabled = True
  109.   Else
  110.     OkayButton.Enabled = False
  111.   End If
  112. End Sub
  113.  
  114. Sub cFieldName_Change ()
  115.   'activate the ok button only if all of the
  116.   'fields have something in it
  117.   If cFieldName <> "" And cFieldType <> "" And Val(cFieldLength) > 0 Then
  118.     OkayButton.Enabled = True
  119.   Else
  120.     OkayButton.Enabled = False
  121.   End If
  122. End Sub
  123.  
  124. Sub cFieldType_Click ()
  125.   'call function to set size and type of field
  126.   cFieldLength = SetFldProperties(CStr(cFieldType))
  127.   cFieldLength.Enabled = False
  128.  
  129.   'enable field length control for string and memo type
  130.   If gwFldType = FT_STRING Then
  131.     'allow entry of field length
  132.     cFieldLength.Enabled = True
  133.     cFieldLength = "0"
  134.   End If
  135.  
  136.   'make sure that there is data in
  137.   'all fields before enabling the ok button
  138.   If cFieldName <> "" Then
  139.     OkayButton.Enabled = True
  140.   Else
  141.     OkayButton.Enabled = False
  142.   End If
  143. End Sub
  144.  
  145. Sub Form_Load ()
  146.   'populate the Field Type list on the form
  147.   If gstDataType = "MS Access" Then
  148.     cFieldType.AddItem "Counter"
  149.   End If
  150.   cFieldType.AddItem "True/False"
  151.   cFieldType.AddItem "Byte"
  152.   cFieldType.AddItem "Integer"
  153.   cFieldType.AddItem "Long"
  154.   cFieldType.AddItem "Currency"
  155.   cFieldType.AddItem "Single"
  156.   cFieldType.AddItem "Double"
  157.   cFieldType.AddItem "Date/Time"
  158.   cFieldType.AddItem "String"
  159.   cFieldType.AddItem "Binary"
  160.   cFieldType.AddItem "Memo"
  161. End Sub
  162.  
  163. Sub Form_Paint ()
  164.   Outlines Me
  165. End Sub
  166.  
  167. Sub OkayButton_Click ()
  168.   On Error GoTo OkayErr
  169.  
  170.   Dim f As New Field     'local field structure
  171.   Dim tbln As String     'table name
  172.  
  173.   'fill the field structure
  174.   f.Name = cFieldName
  175.   'get field length from form for string and memo
  176.   If gwFldType = FT_STRING Then
  177.     gwFldSize = Val(cFieldLength)
  178.   End If
  179.   f.Type = gwFldType
  180.   f.Size = gwFldSize
  181.   If cFieldType = "Counter" Then
  182.     f.Attributes = &H10   'counter type
  183.   End If
  184.  
  185.   tbln = fTables.cTableList
  186.   If gfAddTableFlag = False Then
  187.     gCurrentDB.TableDefs(tbln).Fields.Append f
  188.   End If
  189.   fTblStru.cFields.Row = 1
  190.   fTblStru.cFields.Col = 0
  191.   If fTblStru.cFields <> "" Then
  192.     'add a row if the first one isn't blank
  193.     fTblStru.cFields.Rows = fTblStru.cFields.Rows + 1
  194.   End If
  195.   fTblStru.cFields.Row = fTblStru.cFields.Rows - 1
  196.   fTblStru.cFields.Col = 0
  197.   fTblStru.cFields = cFieldName
  198.   fTblStru.cFields.Col = 1
  199.   fTblStru.cFields = cFieldType
  200.   fTblStru.cFields.Col = 2
  201.   fTblStru.cFields = cFieldLength
  202.   If fTblStru.cFields.Rows < 12 Then
  203.     fTblStru.cFields.Height = fTblStru.cFields.Rows * 245
  204.     fTblStru.FieldBox.Height = fTblStru.cFields.Height + 360
  205.     fTblStru.IndexBox.Top = fTblStru.FieldBox.Top + fTblStru.FieldBox.Height + 250
  206.     fTblStru.Height = fTblStru.IndexBox.Top + fTblStru.IndexBox.Height + 500
  207.   End If
  208.  
  209.   'clear the name and allow entry of another
  210.   cFieldName = ""
  211.   cFieldName.SetFocus
  212.   GoTo OkayEnd
  213.  
  214. OkayErr:
  215.   ShowError
  216.   Resume OkayEnd
  217.  
  218. OkayEnd:
  219.  
  220. End Sub
  221.  
  222.